package com.itheima.d4_create_thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class ThreadTest3Practice {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Calculator1 calculator1 = new Calculator1(100);
        FutureTask<Long> futureTask = new FutureTask<>(calculator1);

        Thread t1 = new Thread(futureTask);
        t1.start();

        Long rs = futureTask.get();
        System.out.println("rs = " + rs);

    }
}

class Calculator1 implements Callable<Long> {
    private long n;

    public Calculator1(long n) {
        this.n = n;
    }

    @Override
    public Long call() throws Exception {
        long sum = 0;
        for (long i = 1; i <= n; i++) {
            sum += i;
        }
        return sum;
    }
}
